import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
Vue.use(VueRouter)
// 获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
// 修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    redirect: '/home',
    //name: 'home',
    //component: HomeView
  },
  {
    path: '/home',
    name: '主页',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    component: () => import('../views/AboutView.vue')
  },
  {
    path: '/userid',
    name: 'userid',
    component: () => import('../views/userid.vue')
  },
  {
    path: '/view',
    name: 'view',
    component: () => import('../views/view.vue')
  },
  {
    path: '/userhome',
    name: 'userhome',
    component: () => import('../views/userhome.vue')
  },
  {
    path: '/login',
    name: '登录',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/register',
    name: '注册',
    component: () => import('../views/Register.vue')
  },
  {
    path: '/result',
    name: '搜索结果',
    component: () => import('../views/Result.vue')
  },
  {
    path: '/exhibit',
    name: '博文',
    component: () => import('../views/Editor.vue')
  },
  {
    path:'*',
    name:'error404',
    component:()=>import('../views/error404.vue')
  }
]

const router = new VueRouter({
  routes
})

export default router
